<?php



/*
 * DEBUG日志类
 * 全局类 不依赖其他类或结构
 * 保持同步 eshop basic wxweb 
 */
class dbt_D extends sing_table {
    private $_FilePath;
    //构造方法
    function __construct() {
        //日志文件夹
        $this->_FilePath = APP_ROOT.DIRECTORY_SEPARATOR.'debug_log';
    }

    private function nDirectory(){
        if(!is_dir($this->_FilePath)){
            mkdir($this->_FilePath,0755);
        }
    }
    //写入日志
    //日志格式  [状态 时间(2016-5-9 09:53:46)] 打印字符串($string)
    //
    public function WriteLogFile($string,$fileName='',$status='FatalError'){
        $this->nDirectory();
        $time = microtime();
        $timeNow = explode(" ", $time);
        /*
         * $status
         * Debug
         * FatalError
         * Warning
         * Success
         */
        //文件名称
        $fileName = $fileName? DIRECTORY_SEPARATOR.$fileName:DIRECTORY_SEPARATOR.date('Y-m',$timeNow[1]).'.log';
        //打开日志文件

        //文件内容
        $content = '['.$status.' '.date('Y-m-d H:i:s',$timeNow[1]).",微秒：".$timeNow[0].'] '.$string." \n";

        //以续写的方式写入文件
        file_put_contents($this->_FilePath.$fileName,$content,FILE_APPEND);
    }
    
    


    public function EchoLogFile($fileName){
        $fileName = $fileName? DIRECTORY_SEPARATOR.$fileName:DIRECTORY_SEPARATOR.date('Y-m',TIME).'.log';
        if(is_file($this->_FilePath.$fileName)){
            echo file_get_contents($this->_FilePath.$fileName);
        }else{
            echo $this->_FilePath.$fileName.' file not found';
        }
    }
}